/*
 * File:   GenericListTest.cpp
 * Author: Enrique Antezana
 *
 * Created on 17-04-2013, 04:31:02 PM
 */

#include "GenericListTest.h"
#include "../src/list/GenericList.h"
#include "../src/list/NotFoundElementException.h"

CPPUNIT_TEST_SUITE_REGISTRATION(GenericListTest);

GenericListTest::GenericListTest() {
}

GenericListTest::~GenericListTest() {
}

void GenericListTest::setUp() {
}

void GenericListTest::tearDown() {
}

void GenericListTest::shouldCreateAnEmptyListTest() {
    GenericList<int> list;

    CPPUNIT_ASSERT(list.size() == 0);

}

void GenericListTest::isEmptyTest() {
    GenericList<int> list;

    bool actualListState = list.isEmpty();

    CPPUNIT_ASSERT(actualListState == true);


}

void GenericListTest::sizeOfListMustBeZeroAfterBeingCreatedTest() {
    GenericList<int> list;

    int actualListSize = list.size();

    CPPUNIT_ASSERT(actualListSize == 0);


}

void GenericListTest::addElementsToTheListTest() {
    GenericList<int> list;

    int elementToBeAdded1 = 1;
    int elementToBeAdded2 = 2;
    int elementToBeAdded3 = 3;
    int elementToBeAdded4 = 4;

    list.add(elementToBeAdded1);
    list.add(elementToBeAdded2);
    list.add(elementToBeAdded3);
    list.add(elementToBeAdded4);

    int actualListSize = list.size();
    int expectedListSize = 4;

    CPPUNIT_ASSERT(actualListSize == expectedListSize);

}

void GenericListTest::removeElementsFromTheList() {
    GenericList<int> list;

    int elementToBeAdded1 = 1;
    int elementToBeAdded2 = 2;
    int elementToBeAdded3 = 3;
    int elementToBeAdded4 = 4;

    list.add(elementToBeAdded1);
    list.add(elementToBeAdded2);
    list.add(elementToBeAdded3);
    list.add(elementToBeAdded4);

    int actualListSize = list.size();
    int expectedListSize = 4;

    CPPUNIT_ASSERT(actualListSize == expectedListSize);

    list.remove(1);
    list.remove(2);
    list.remove(3);
    list.remove(4);

    actualListSize = list.size();
    expectedListSize = 0;

    CPPUNIT_ASSERT(actualListSize == expectedListSize);

}

void GenericListTest::shouldntRemoveAnElementIfThisDoesntExistTest() {
    GenericList<int> list;

    int elementToBeAdded1 = 1;
    int elementToBeAdded2 = 2;

    list.add(elementToBeAdded1);
    list.add(elementToBeAdded2);
    try {
        list.remove(3);
    } catch (NotFoundElementException& e) {
        CPPUNIT_ASSERT_THROW(list.remove(3), NotFoundElementException);

    }

}

void GenericListTest::getAnElementGivenAPositionTest() {
    GenericList<int> list;

    list.add(1);
    list.add(2);

    int actualElementValue = list.get(1);
    int expectedValue = 2;

    CPPUNIT_ASSERT(actualElementValue == expectedValue);
}

void GenericListTest::shouldntGetAnElementInAnInvalidPositionTest() {
    GenericList<int> list;

    int elementToBeAdded1 = 1;
    int elementToBeAdded2 = 2;

    list.add(elementToBeAdded1);
    list.add(elementToBeAdded2);


    try {
        list.get(3);
    } catch (NotFoundElementException& e) {
        CPPUNIT_ASSERT_THROW(list.get(3), NotFoundElementException);

    }

}